<template>
	<div class="mainCon panelsList">
		<div class="containercontent">
			<div class="selectw100 seachTip">
				<div class="inlineblock verticalmiddle infoitem">
					<div class="inlineblock verticalmiddle">
						能力参数
					</div>
					<div class="inlineblock verticalmiddle informationItem">
						<el-select v-model="detectability" filterable remote :remote-method="readDetectList" style="width:100%;" size="mini" ref="selectAbility" @change="getTestBatchs(testItemQuery,'search')">
							<el-option v-for="item in abilityOptions" :key="item.id" :label="'【' + item.version + '】' + item.name " :value="item.id">
							</el-option>
						</el-select>
					</div>
				</div>
        <div class="inlineblock verticalmiddle infoitem">
        	<div class="inlineblock verticalmiddle">
        		任务
        	</div>
        	<div class="inlineblock verticalmiddle informationItem" style="width:calc(100% - 50px)">
        		<el-select v-model="task" filterable style="width:100%;" size="mini" @change="getTestBatchs(testItemQuery,'search')">
        			<el-option v-for="(item,index) in taskList" :key="item.index" :label="item" :value="item">
        			</el-option>
        		</el-select>
        	</div>
        </div>
				<div class="inlineblock verticalmiddle infoitem">
					<div class="inlineblock verticalmiddle">
						检测单筛选
					</div>
					<div class="inlineblock verticalmiddle informationItem">
						<el-select v-model="testValue" size="mini" @change="getTestBatchs(testItemQuery,'search')">
							<el-option v-for="item in testOptions" :key="item.value" :label="item.label" :value="item.value">
							</el-option>
						</el-select>
					</div>
				</div>
				<div class="inlineblock verticalmiddle searchIcon" style="margin-left:15px;">
					<el-button size="mini" @click="getTestBatchs(testItemQuery,'search')">搜索</el-button>
				</div>
				<div class="inlineblock verticalmiddle searchIcon">
					<el-button size="mini" @click="emptySearch">清空</el-button>
				</div>

			</div>

			<div class="separaterowTable">
				<div class="tableTittle">
					<div>
						<span class="fontImpact">1</span>
						<span>检测单</span>
					</div>
				</div>
				<el-table :data="tableData" style="width: 100%" class="tableCon" size="mini" highlight-current-row cell-class-name="batchtablecell" @current-change="testbatchrowselect">
					<el-table-column prop="pihao" label="序号" width="55px">
						<template slot-scope="scope">
							{{scope.$index+(testItemQuery.page - 1) * testItemQuery.pageCount + 1}}
						</template>
					</el-table-column>
					<el-table-column prop="code" label="检测单编号" min-width="110px" show-overflow-tooltip>
					</el-table-column>
					<el-table-column prop="detectabilityName" label="能力参数" min-width="170px" show-overflow-tooltip>
					</el-table-column>
					<el-table-column prop="taskNames" label="任务名称" min-width="170px" show-overflow-tooltip>
						<template slot-scope="scope">
							{{scope.row.taskNames == undefined ? '---':scope.row.taskNames}}
						</template>
					</el-table-column>

					<el-table-column prop="analystName" label="检测人员" min-width="70px">
					</el-table-column>
					<el-table-column prop="status" label="状态" :formatter="formatterStatus" min-width="70px">
					</el-table-column>
					<el-table-column prop="createByName" label="创建人" min-width="70px">
					</el-table-column>
					<el-table-column prop="createTime" label="创建时间" width="130px" :formatter="formatterDate">
					</el-table-column>

					<el-table-column label="操作" min-width="120px">
						<template slot-scope="scope">
							<el-button @click="editbatch(scope.row)" type="text" size="small" v-if="userOpernation.update.display">设置</el-button>
							<el-button @click="deleteBatch(scope.row)" type="text" size="small" v-if="userOpernation.delete.display">删除</el-button>
						</template>
					</el-table-column>
				</el-table>
				<div class="block changepages">
					<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="testItemQuery.page" :page-sizes="[20,30,40]" :page-size="testItemQuery.pageCount" layout="total, sizes, prev, pager, next, jumper" :total="rowNumber">
					</el-pagination>
				</div>
			</div>
		</div>
		<div v-if="editpanelshow" class="editpanelPop">
			<div class="editpanel twoStageWindow">
				<div class="twoStageWindowTitle">
					设置检测单 <span style = "margin-left:8px;font-size:13px;" v-if="!testpanelForm.doSub">{{testpanelForm.detectabilityName}}</span>
					<span style="color:#3499ff;"></span>
					<div class="twoStageWindowClose">
						<el-button size="mini" type="primary" @click="subUpdatebatch" :disabled="!isRepeat">提交</el-button>
						<el-button size="mini" v-on:click="closePanel">取消</el-button>
					</div>
				</div>
				<div class="containercontent" style="margin-top:40px;height:calc(100% - 40px);padding-top: 0;"
        v-loading="isLoading"
        element-loading-text="正在验证质控..."
        element-loading-spinner="el-icon-loading"
        >
					<div class="form">
						<el-form label-width="110px" :inline="false" class="demo-form-inline" :model="testpanelForm" ref="testpanelForm" :rules="testpanelRules">
							<el-form-item label="主仪器" prop="equipment" v-if="!testpanelForm.doSub">
								<el-col :span="22">
									<el-select v-model="testpanelForm.equipment" placeholder="请选择" size="mini" filterable>
										<el-option v-for="item in mainequipment" :key="item.equipment" :label="item.name" :value="item.equipment">
										</el-option>
									</el-select>
								</el-col>
							</el-form-item>
							<el-form-item label="辅助仪器" prop="assistEquipment" v-if="!testpanelForm.doSub">
								<el-col :span="22">
									<!--<el-cascader :options="assEquipment" :props="propsEquipment" v-model="outEquipment" size="mini" style="width:100%" filterable clearable>
									</el-cascader>-->

									<el-select v-model="testpanelForm.assistEquipment" placeholder="请选择" size="mini" multiple collapse-tags>
										<el-option v-for="item in assEquipment" :key="item.equipment" :label="item.name" :value="item.equipment">
										</el-option>
									</el-select>
								</el-col>
							</el-form-item>
              <el-form-item :label="stationName" prop="offices">
                <el-col :span="22">
                  <el-select v-model="testpanelForm.offices" placeholder="请选择" size="mini" >
                    <el-option label="全部" value="ALL"></el-option>
                    <el-option v-for="item in stationList" :key="item.id" :label="item.name" :value="item.id">
                    </el-option>
                  </el-select>
                </el-col>
              </el-form-item>
              <el-form-item label="检测人" prop="analyst">
              	<el-col :span="22">
              		<el-select v-model="testpanelForm.analyst" size="mini" filterable remote :remote-method="readUser">
              			<el-option v-for="item in userData" :key="item.account" :label="item.name" :value="item.account" :disabled="item.disabled">
              			</el-option>
              		</el-select>
              	</el-col>
              </el-form-item>
							<el-form-item label="校核人员" prop="checker">
								<el-col :span="22">
									<el-select v-model="testpanelForm.checker" placeholder="请选择" size="mini" filterable>
										<el-option v-for="item in userData" :key="item.account" :label="item.name" :value="item.account" :disabled="item.disabled">
										</el-option>
									</el-select>
								</el-col>
							</el-form-item>
							
							<el-form-item label="审核人员" prop="auditor">
								<el-col :span="22">
									<el-select v-model="testpanelForm.auditor" placeholder="请选择" size="mini" filterable clearable>
										<el-option v-for="item in userData" :key="item.account" :label="item.name" :value="item.account" :disabled="item.disabled">
										</el-option>
									</el-select>
								</el-col>
							</el-form-item>
							<el-form-item label="共同完成人" prop="togetherWith">
								<el-col :span="22">
									<el-select v-model="testpanelForm.togetherWith" placeholder="请选择" size="mini" filterable clearable>
										<el-option v-for="item in userData" :key="item.account" :label="item.name" :value="item.account" :disabled="item.disabled">
										</el-option>
									</el-select>
								</el-col>
							</el-form-item>

						</el-form>
					</div>
					<div class="elTab">
						<el-tabs style="width:100%;">
							<el-tab-pane label="已领样品">
								<div class="inlineblock verticalmiddle width100" style="margin-bottom:8px;">
									<el-button type="primary" size="mini" style="float:right;margin-left:8px;" @click="addSample">添加样品</el-button>
									<el-button type="primary" size="mini" @click="lookStandardSeriesShow('new')" style="float:right" v-if="testpanelForm.doUseCurve && !testpanelForm.hasCriterion && !testpanelForm.doSub">添加标准系列</el-button>
									<el-button type="primary" size="mini" @click="lookStandardSeriesShow('edit')" style="float:right" v-if="testpanelForm.doUseCurve && testpanelForm.hasCriterion && !testpanelForm.doSub">查看标准系列</el-button>
									<el-button type="primary" size="mini" @click="addQCShow" style="float:right" v-if="!testpanelForm.doSub">添加QC</el-button>
								</div>
								<el-table :data="testpanelForm.sampleBeans" style="width: 100%;" class="tableCon" @selection-change="handleSelectionChange" size="mini">
									<el-table-column type="selection" width="38px" :selectable='selectInit'>
									</el-table-column>
									<el-table-column property="beihao" label="序号" width="50px">
										<template slot-scope="scope">
											{{scope.$index+1}}
										</template>
									</el-table-column>
									<el-table-column property="sampleCode" label="样品编号" min-width="100px" :show-overflow-tooltip="true">

									</el-table-column>
									<el-table-column label="样品名称" min-width="100px" property="sampleName" key = "sampleName" :show-overflow-tooltip="true" v-if="!testpanelForm.doSub">
										<template slot-scope="scope">
											{{scope.row.doBlind ? '***':scope.row.sampleName}}
										</template>
									</el-table-column>
									<el-table-column label="样品名称" min-width="100px" property="sampleName" key = "sampleNameSub"  :show-overflow-tooltip="true" v-if="testpanelForm.doSub">

									</el-table-column>
									<el-table-column prop="detectabilityName" label="能力参数" min-width="160px"  key = "detectability" show-overflow-tooltip v-if="testpanelForm.doSub">
									</el-table-column>
									<el-table-column label="任务名称" min-width="100px" property="taskName" :show-overflow-tooltip="true"  key = "taskName"  v-if="!testpanelForm.doSub">
										<template slot-scope="scope">
											{{scope.row.doBlind ? '***':(scope.row.taskName == undefined ? '---':scope.row.taskName)}}
										</template>
									</el-table-column>
									<el-table-column label="任务名称" min-width="100px" property="taskName" :show-overflow-tooltip="true" key = "taskNameSub"  v-if="testpanelForm.doSub">

									</el-table-column>
									<el-table-column property="qcTypeName" label="QC类型" min-width="100px" :formatter="formatterQcType"  key = "qcTypeName" width="100px" v-if="!testpanelForm.doSub">
										<template slot-scope="scope">
											{{scope.row.doBlind ? '***':scope.row.qcTypeName}}
										</template>
									</el-table-column>
									<el-table-column property="parentCode" min-width="100px" :show-overflow-tooltip="true" key = "parentCode" label="父样编号" width="120px" v-if="!testpanelForm.doSub">
										<template slot-scope="scope" >
											{{scope.row.doBlind ? '***':scope.row.parentCode}}
										</template>
									</el-table-column>
									<el-table-column property="doStandard" label="是否标准系列" min-width="80px" key = "isStandard" :formatter="formatterBlind" v-if="!testpanelForm.doSub">
										<template slot-scope="scope">
											{{scope.row.doBlind ? '***':(scope.row.doStandard ? '是':(scope.row.doStandard == false ?'否':''))}}
										</template>
									</el-table-column>
									<el-table-column property="subcontractorName" min-width="100px" label="分包商" key = "isSub" v-if="testpanelForm.doSub" :show-overflow-tooltip="true">

									</el-table-column>
									<el-table-column label="操作" width="80px">
										<template slot-scope="scope">
											<el-button type="text" size="small" @click="deleteReceived(scope.row,scope.$index)" :disabled="scope.row.doStandard">删除</el-button>
										</template>
									</el-table-column>
								</el-table>
							</el-tab-pane>
						</el-tabs>
					</div>
				</div>
			</div>
		</div>
		<!--添加标准系列弹框-->
		<standseries :addVisible.sync="standardseriesshow" :newOrEdit="newOrEdit" :standardSeriesDetail="standardSeriesForm" :userData="userData" :allUnit="allUnit" :testpanelDetail="testpanelForm" :standarModel="standarModel"></standseries>

		<!--添加样品弹框-->
		<el-dialog :visible.sync="addSamplepop" width="70%" :show-close='false' :closeOnClickModal='false' class="addSampleForm addSampleForm1" ref="addSampleForm">
			<span slot="title" class="dialog-title">
				选择样品
				<el-button @click="toggleSelect" size="mini" class="popupClose">关闭</el-button>
			</span>
			<div style="width:100%;float:right;" class="sampleList">
				<!--:isZuJian="true" :index="true" :noadd="false" ref="sampleList"  v-on:selectedItem="sampleList" -->
				<sampleReceived :isZuJian="true" :detectability="zujianDetectability" :testpanelForm="testpanelForm" @showParentComp="eventFromChild" ref="addsampleRef"></sampleReceived>
			</div>
			<span slot="footer" class="dialog-footer">
				<el-button type="primary" @click="subAddSample" size="mini">确定</el-button>
				<el-button size="mini" @click="toggleSelect">取 消</el-button>
			</span>
		</el-dialog>
		<!--添加QC弹框-->
		<el-dialog :visible.sync="addqcShow" width="70%" :show-close='false' :closeOnClickModal='false' class="addSampleForm addQCdialog" ref="addQC">
			<span slot="title" class="dialog-title">
				添加QC样品
				<el-button @click="closeaddqcShow" size="mini" class="popupClose">关闭</el-button>
			</span>
			<el-tabs v-model="activeName">
				<el-tab-pane label="QC样品" name="first">
					<!--<div class="padd10">
					<div class=" width100 ">
						<el-button size="mini" type="primary" style="float:right"  @click="lookQcPlan">查看质控计划</el-button>
					</div>
				</div>-->
					<ul class="padd10 sampleType" style="clear:both;">
						<li v-for="(item,index) in qcList" :key="item.code"  :class="{sample3 : item.genre == '3','width100':true,'inlineblock':true}">

							<div class="inlineblock verticalmiddle text85" v-if="item.genre == 'QCB02' || item.genre == 'QCB01'">{{item.name}}</div>
							<div class="inlineblock verticalmiddle" v-if="item.genre == 'QCB02'">
								<el-checkbox v-model="item.checkboxModel" :disabled="!hasParentSample && item.genre == 'QCB02'"></el-checkbox>

							</div>
							<!--QCB02无父样 QCB01有父样 -->
							<div class="inlineblock with70" v-if="item.genre == 'QCB01'">
								<el-checkbox v-model="item.checkboxModel" :disabled="hasParentSample && item.genre == 'QCB01'"></el-checkbox>
								<!--:disabled="hasParentSample && item.genre == 'QCB01'"-->
								<el-input-number  v-model="item.inputModel" :min="0" :step = "2"   size="mini"  disabled class="controlsPosition"></el-input-number>
							</div>
						</li>
						<li :class="{'width100':true,'inlineblock':true}">
							<div class="inlineblock verticalmiddle text85">加标父样</div>
							<el-checkbox v-model="checkboxParent" :disabled="!hasParentSample"></el-checkbox>
						</li>
					</ul>
					<!--<el-input-number v-model="num" :step="2" step-strictly></el-input-number>-->
					<!--<ul>  //正确写法
					<li v-for="(item,index) in standarQc" :key="item.code">
						<div class="inlineblock verticalmiddle text85">{{item.name}}</div>
						<div class="inlineblock verticalmiddle informationItem">
							<el-transfer v-model="monitoringPointsValue" :data="monitoringPoints" filterable :titles="['待选标准样品', '已选标准样品']"></el-transfer>
						</div>
					</li>
				</ul>-->
					<div class=" width100 " style="height:calc(100% - 150px);overflow:auto;">
						<div class="inlineblock verticalmiddle">
							标准样品
						</div>
						<div class="inlineblock verticalmiddle informationItem">
							<el-transfer v-model="monitoringPointsValue" :data="monitoringPoints" :props="{key: 'id',label: 'nameBatch'}" filterable :titles="['待选标准样品', '已选标准样品']" class="transferQc"></el-transfer>
						</div>
					</div>
				</el-tab-pane>
				<el-tab-pane label="质控计划" name="second">
					<div style = "width:40%;float:left;height:calc(100% - 5px);">
						<el-table :data="qcPlanList" style="width: 100%;height:100%;" border size="mini" @row-click = "rowclickQcplan" highlight-current-row class = "tableCon" ref = "qcTable">
							<el-table-column label="序号"  width="50px">
								<template slot-scope="scope">
									{{scope.$index+1}}
								</template>
							</el-table-column>
							<el-table-column property="name" min-width="100px"  label="名称" :show-overflow-tooltip="true">
							</el-table-column>
							<el-table-column property="typeName" label="类型" min-width="100px" :show-overflow-tooltip="true">
							</el-table-column>
						</el-table>
					</div>
					<div style = "width:58%;float:right;height:100%" v-if = "qcPlanList.length != 0">
						<div style = "height:30px;line-height:30px;color:#999">
							<p style = "float:left;width:48%">计划名称: <span>{{qcPlanDetail.name}}</span></p>
							<p style = "float:right;width:48%">质控类型: <span>{{qcPlanDetail.typeName}}</span></p>
						</div>
						<div style = "height:30px;line-height:30px;color:#999">
							<p style = "float:left;width:48%">计划周期: {{qcPlanDetail.conditionName}}</p>
							<p style = "float:right;width:48%">质控样品量: {{qcPlanDetail.number}}</p>
						</div>


						<el-table :data="qcPlanDetail.qcValueBeanList" border style="width: 100%;height:calc(100% - 65px);" class = "tableCon" size="mini" >
							<el-table-column label="序号"  width="50px">
								<template slot-scope="scope">
									{{scope.$index+1}}
								</template>
							</el-table-column>
							<el-table-column property="concenLow" min-width="80px"  label="测试结果浓度下限(mg/L)" >
							</el-table-column>
							<el-table-column property="concenHigh" label="测试结果浓度上限(mg/L)" min-width="80px" >
							</el-table-column>
							<el-table-column property="low" label="判断下限(%)" min-width="80px" >
							</el-table-column>
							<el-table-column property="high" min-width="80px"  label="判断上限(%)">
							</el-table-column>

						</el-table>
					</div>

				</el-tab-pane>
			</el-tabs>
			<span slot="footer" class="dialog-footer">
				<el-button type="primary" @click="subQC" size="mini">确 定</el-button>
				<el-button size="mini" @click="closeaddqcShow">取 消</el-button>
			</span>
		</el-dialog>

	</div>
</template>

<script>
import $ from 'jquery'
import { mapState } from 'vuex'
import { Notification } from 'element-ui';

const standseries = () => import('./children/standarSeries.vue');
const sampleReceived = () => import('../samplemanage/yangpinlingqu.vue');


export default {
	data() {
		let that = this;
		const generateData = _ => {
			const data = [];
			for (let i = 1; i <= 15; i++) {
				data.push({
					key: i,
					label: `标准样品 ${i}`
				});
			}
			return data;
		};
		return {
			num:0,
			userInfo: {},
			detectability: '', //搜索框能力参数绑定值
			abilityOptions: [], //能力参数选项
			tableData: [], //检测列表数据
			testOptions: [  //检测筛选选项
				{
					value: 1,
					label: '我的'
				},
				{
					value: 0,
					label: '全部'
				}
			],
			testValue: 1, //检测筛选绑定值
			testItemQuery: { //分页信息
				page: 1,
				pageCount: 20
			},
			rowNumber: 0,
			editpanelshow: false, //
			testpanelForm: {  //检测单表单
				analyst: "",
				assistEquipment: [],
				equipment: "",
				checker: "",
				togetherWith: "",
				auditor: "",
				sampleBeans: [],
        offices:"",
			},
			testpanelRules: {
        equipment: [
        	{ required: true, message: '请选择仪器类型', trigger: 'change' },
        ],
        checker: [{ required: true, message: '请选择校核人员', trigger: 'change' }],
        offices:[{ required: true, message: '请选择', trigger: 'blur' }],
			},
			equipmentType: '',//主仪器接口要传测id
			mainequipment: [], //主仪器数据
			userData: [], //检测人数据
			allUnit: [], //单位
			multipleSelection: [],  //已选样品勾选的数据
			addSamplepop: false, //添加样品弹框
			zujianDetectability: '', //传给子组件的能力参数
			rowId: '', //设置这一行检测单的id
			receivedSapmle: [], //要提交的已领样品
			standardseriesshow: false,
			newOrEdit: 'new', //是编辑还是添加标准系列
			standardSeriesForm: {
				code: '',
				configDate: null,
				temperature: '',
				humcodeity: '',
				doUse: false,
				checker: '',
				configMan: JSON.parse(sessionStorage.getItem('laboratoryAccountInfo')).loginid,
			},
			breakFlag: 1, //是否中断提交
			disabledUnit: true, //是否禁止填写单位
			addqcShow: false, //添加QC弹框
			monitoringPointsValue: [], //穿梭器左边的值
			monitoringPoints: [], //qc样品中标准样品
			hasParentSample: false, //默认没有选中父样
			assEquipment: [], //辅助仪器信息
			propsEquipment: { //辅助仪器继承的值
				label: 'name',
				value: 'id',
				children: 'children'

			},
			outEquipment: [], //辅助仪器要传的值
			qcList: [],  //qc分类
			allQcList: [], //所有的qc类型
			standarQc: [], //qc分类中的标样
			standarModel: "mygrouptest", //检测安排模块的标准系列弹框
			isRepeat: true,
			activeName: "first",
			qcPlanList:[], //质控计划列表
			qcPlanDetail:{},
			checkboxParent:false,
      taskList:[],
      task:"",
      isLoading:false,
      stationName:"厂站",
      stationList:[],
		}
	},
	watch: {
		// 监听分页变化
		testItemQuery: {
			handler(val, oldVal) {
				this.getTestBatchs(this.testItemQuery)
			},
			deep: true
		},
		// readAllUnit
		standardseriesshow(val, oldVal) {
			if (val) {
				this.readAllUnit('');
			}
		},
		standarpointsdata: function(val) {
			// console.log(1)
		},
		activeName(val){
			if(val == 'second'){
				this.lookQcPlan()
			}
		}


	},
	props: ['userOpernation'],
	components: {
		sampleReceived, standseries
	},
	mounted() {
		this.$store.dispatch('dogetDictionary')
		this.userInfo = JSON.parse(sessionStorage.getItem('laboratoryAccountInfo')); //获取存储的用户信息
		this.readTask();
    this.readDetectList(''); //搜索能力参数选项
		this.getTestBatchs(this.testItemQuery);
		var a=[1,2,3,4,5]

		var b=[2,3,7,8,9]


		console.log(a.filter(item=>b.indexOf(item)==-1))
	},
	computed: {
		...mapState(['testBatchStatus', 'yesorno', 'typeQcSelect']),

	},

	methods: {
		//查看质控计划
		lookQcPlan() {
			this.$http({
				method: 'post',
				apiUrl: '/qc/getQcMeasureByDetect.htm',
				params: { detectability: this.testpanelForm.detectability },
				isJson: false
			}).then(res => {
				if (res.code == 0) {
					this.qcPlanList = res.data;
					this.rowclickQcplan(res.data[0])
					this.$nextTick(() => {
						this.$refs.qcTable.setCurrentRow(res.data[0]);
					})
				}

			})
		},
		rowclickQcplan(row, column, event){
			// console.log(row)
			this.qcPlanDetail = row
		},
		readAllUnit(item) {
			this.allUnit = [];
			this.$http({
				method: 'post',
				apiUrl: '/technology/readLabUnitList.htm',
				params: { ename: item },
				isJson: true
			}).then(res => {
				if (res.code == 0) {
					this.allUnit = res.data;
				}

			})
		},

		formatterQcType(row, column, cellValue, index) {
			return this.util.codeChangeName({ cellValue: cellValue, list: this.allQcList })
		},
		// 处理状态
		formatterStatus(row, column, cellValue, index) {

			return this.util.changeStatus({ cellValue: cellValue, list: this.testBatchStatus })
		},
		// 过滤是否父样
		formatterBlind(row, column, cellValue, index) {
			return this.util.changeStatus({ cellValue: cellValue, list: this.yesorno })
		},
		// 处理时间
		formatterDate(row, column, cellValue) {
			return cellValue.substring(0, 16)
		},
		// // 验证检测人员，校核人员，审核人员不能相同
		// validateAnalyst(val){
		// 	console.log(val)
		// },
		//   搜索能力参数
		readDetectList(item) {
			this.$http({
				method: 'post',
				apiUrl: '/technology/readDetectList.htm',
				params: { name: item },
				isJson: false
			}).then(res => {
				if (res.code == 0) {
					this.abilityOptions = res.data
				}
			})
		},
    //   搜索能力参数
    readTask() {
    	this.$http({
    		method: 'post',
    		apiUrl: '/detection/getBatchTasks.htm',
    		params: { status: '530' },
    		isJson: false
    	}).then(res => {
    		if (res.code == 0) {
    			this.taskList = res.data
    		}
    	})
    },
		emptySearch() {  //清空数据
			this.detectability = '';
			this.testValue = 0;
      this.task = "";
			this.getTestBatchs(this.testItemQuery, 'search')
		},
		// 读取用户
		readUser(item) {
			this.$http({
				method: 'post',
				apiUrl: '/resource/readEmployeeByLab.htm',
				params: { name: item },
				isJson: true,
			}).then(res => {
				if (res.code === 0) {
					this.userData = res.data;

				}

			})
		},
		// 检测列表数据
		getTestBatchs(parp, search) {
			var analyst = '';
			if (this.testValue == '1') {
				analyst = this.userInfo.loginid
			} else {
				analyst = '';
			};
			var data = {
				detectability: this.detectability,
				analyst: analyst,
				status: 530,
				group: 1,
        taskName:this.task,
				page: parp.page,
				pageCount: parp.pageCount,
			};
			if (search != undefined) {
				this.testItemQuery.page = 1;
				data.page = 1;
				data.pageCount = parp.pageCount;
			} else {
				data.page = parp.page;
				data.pageCount = parp.pageCount;
			}

			this.$http({
				method: 'post',
				apiUrl: '/detection/getTestBatchs.htm',
				params: data,
				isJson: true
			}).then(res => {
				if (res.code == 0) {
					this.tableData = res.data;
					if (!res.pageinfo) {
						this.rowNumber = 0;
					} else if (res.pageinfo && !res.pageinfo.rowNumber) {
						this.rowNumber = 0;
					} else {
						this.rowNumber = res.pageinfo.rowNumber;
					}
				}
			})
		},
		// 编辑检测单
		editbatch(row) {
			this.editpanelshow = true;
			this.readQcList();
			this.zujianDetectability = row.detectability;
			this.rowId = row.id;
			this.$http({
				method: 'post',
				apiUrl: '/detection/getTestBatch.htm',
				params: {
					id: row.id,
					key: 1
				},
				isJson: false
			}).then(res => {
				if (res.code == 0) {
          this.stationName = this.util.getStationName()
          this.stationList = this.util.getStationList()

          // checkNum如果为1 ，审核人为必填字段，否则不必填
					if(res.data.checkNum == 1){
            var arr = [{ required: true, message: '请选择审核人员', trigger: 'change' }]
            this.$set(this.testpanelRules,'auditor',arr)
          }
          for (var i in res.data) {
          	this.testpanelForm[i] = res.data[i]
          }
          if(!this.testpanelForm.offices){
            this.testpanelForm.offices = 'ALL'
          }
					var arr = [];
					if(res.data.assistEquipment != undefined && res.data.assistEquipment != '' && res.data.assistEquipment != null){
						var result = res.data.assistEquipment.indexOf(";")
						if(result != -1){ //含有;
							arr = res.data.assistEquipment.join(';')
						}else{
							arr.push(res.data.assistEquipment)
						}
					}
					this.testpanelForm.assistEquipment = arr;
					this.testpanelForm.sampleBeans = this.sampleSort(this.testpanelForm.sampleBeans)
					this.equipmentType = res.data.equipmentType;
					this.readUser('');
					if(!res.data.doSub){
						this.readEquipmentList();
					}


				}
			})

		},
		deleteBatch(row) {
			this.$confirm('是否删除', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(() => {
				this.$http({
					method: 'post',
					apiUrl: '/detection/deleteTestBatch.htm',
					params: row,
					isJson: true
				}).then(res => {
					if (res.code == 0) {
						this.$message({
							type: 'success',
							message: '删除成功'
						})
						this.getTestBatchs(this.testItemQuery)
					}
				})
			}).catch(() => {
				this.$message({
					type: 'info',
					message: '已取消删除'
				});
			});
		},
		// 获取主仪器
		readEquipmentList() {
			// var data = {
			// 	id: this.equipmentType,
			// }
			// this.$http({
			// 	method: 'post',
			// 	apiUrl: '/resource/readEquipmentListById.htm',
			// 	params: data,
			// 	isJson: false
			// }).then(res => {
			// 	if (res.code == 0) {
			// 		this.mainequipment = res.data;
			// 	}
			// })
			console.log(this.testpanelForm)
			var data = {
				id: this.testpanelForm.detectability,
			}
			this.$http({
				method: 'post',
				apiUrl: '/technology/readEquipmentBeanList.htm',
				params: data,
				isJson: false
			}).then(res => {
				if (res.code == 0) {
					this.mainequipment= []
					this.assEquipment = []
					for(var i in res.data){
						if(res.data[i].isMain){
							this.mainequipment.push(res.data[i])
						}else{
							this.assEquipment.push(res.data[i])
						}
					}
				}
			})
		},
		// 获取辅助仪器信息
		assistEquipmentList() {
			var data = {
				id: this.equipmentType,
			}
			this.$http({
				method: 'post',
				apiUrl: '/resource/readEquipCombobox.htm',

			}).then(res => {
				if (res.code == 0) {
					// this.assEquipment = res.data;
					// this.outEquipment = this.getTreeDeepArr(this.testpanelForm.assistEquipment, this.assEquipment)

				}
			})
		},
		// 处理绑定的值
		getTreeDeepArr(key, treeData) {

			let arr = []; // 在递归时操作的数组
			let returnArr = []; // 存放结果的数组
			let depth = 0; // 定义全局层级
			// 定义递归函数
			function childrenEach(childrenData, depthN) {

				for (var j = 0; j < childrenData.length; j++) {
					depth = depthN; // 将执行的层级赋值 到 全局层级
					arr[depthN] = (childrenData[j].id);
					if (childrenData[j].id == key) {
						// returnArr = arr; // 原写法不行, 因 此赋值存在指针关系
						returnArr = arr.slice(0, depthN + 1); //将目前匹配的数组，截断并保存到结果数组，
						break
					} else {
						if (childrenData[j].children) {
							depth++;
							childrenEach(childrenData[j].children, depth);
						}
					}
				}
				return returnArr;
			}
			return childrenEach(treeData, depth);
		},
		// 删除已领样品
		deleteReceived(row, index) {
			var sampleArr = JSON.parse(JSON.stringify(this.testpanelForm.sampleBeans));
			var deleteArr = [];
			// 加唯一标识 用于删除
			for(var i in sampleArr){
				this.$set(sampleArr[i],"deleteKey",this.util.generateMixed({number:32}))
			}
			// 现场 有父样 （现场平行，现场加标）不能删除
			if(row.space == 1 && row.group == 1){
				this.$notify({
					message:row.sampleName + "为"+ row.qcTypeName + ",不能被删除!",
					title:"警告",
					type:"warning"
				})
				return;
			}
			//如果是室内无父样 代表是 空白 一起删除    //如果要删除的样品是普通样，找到他的所有子样一起删除
			if((row.space == 2 && row.group == 2) || (row.parent != undefined && row.parent !="" && row.parent != null && (row.qcType == ""  || row.qcType == null || row.qcType == undefined))){
				for(var i in sampleArr){
					if(row.parent == sampleArr[i].parent){
						deleteArr.push(sampleArr[i])
					}
				}
			}else{
				deleteArr.push(sampleArr[index])

			}
			var deleteArrKey = []
			for(var i in deleteArr){
				deleteArrKey.push(deleteArr[i].deleteKey)
				if(deleteArr[i].id != undefined){
					this.deleteBatchSample(deleteArr[i]).then(res =>{})
				}
			}
			const result = sampleArr.filter(item => !deleteArrKey.includes(item.deleteKey));
			this.testpanelForm.sampleBeans = result;


		},
		deleteBatchSample(row){
			return new Promise((resolve, reject) => {
				this.$http({
					method: 'post',
					apiUrl: '/detection/deleteBatchSample.htm',
					params: row,
					isJson: true,
				}).then(res => {
					if (res.code == 0) {
						resolve(res)
					}
				})
			})

		},
		// 添加样品
		addSample() {
			this.addSamplepop = true;
			this.$nextTick(() => { //弹出现调用子组件的方法
				var row = {detectability:this.zujianDetectability}
				this.$refs.addsampleRef.changeAbility(row)
				this.$refs.addsampleRef.readSample()
			})
		},
		// 从子组件中得到的已领样品数据，
		eventFromChild(dataIf) {
			this.receivedSapmle = dataIf
		},
		// 确认添加普通样品
		subAddSample() {
			if (this.receivedSapmle.length == 0) {
				this.$message({
					type: 'info',
					message: '请先选择至少一个样品'

				})
			} else {
				if(this.testpanelForm.doSub){
					this.testpanelForm.sampleBeans = this.util.repeatData({ old: this.testpanelForm.sampleBeans, new: this.receivedSapmle, unique: 'id',sort:"order" })
					this.toggleSelect();
					this.receivedSapmle = [];
				}else{
					this.verifyBatchQc().then(() =>{
						this.testpanelForm.sampleBeans = this.util.repeatData({ old: this.testpanelForm.sampleBeans, new: this.receivedSapmle, unique: 'id',sort:"order" })
						this.toggleSelect();
						this.receivedSapmle = [];
					})
				}

			}

		},
		verifyBatchQc(){
			return new Promise((resolve, reject) => {
				this.$http({
					method: 'post',
					apiUrl: '/detection/verifyBatchQc.htm',
					params: this.receivedSapmle,
					isJson: true,
				}).then(res => {
					if (res.code === 0) {
						resolve(res)
					}

				})
			})

		},
		//样品排序
		sampleSort1(arr) {
			// console.log(arr)
			var temp1 = [];//第一，标准系列样品
			var temp2 = [];//第二，QC空白样品
			var temp3 = [];//第三，平行样品，或者加标样品
			var temp4 = [];//第四，普通样品
			var temp5 = [];//第五，标准样品
			for (var i in arr) { //遍历所有需要排序的样品
				var obj = arr[i];
				if (obj.doStandard) { //标准系列样品
					temp1.push(obj);
				} else if (obj.qcType != null && obj.qcType != "" && obj.qcType != undefined) {//该样品为QC样品
					if (obj.genre == "QCA01" || obj.genre == "QCB01" || obj.genre == "QCB03") { //该样品为无父样 为空白样品 或者 标准样品
						// console.log(obj.standardSample)
						if (obj.standardSample != null && obj.standardSample != "" && obj.standardSample != undefined) {//该样品标准样品
							temp5.push(obj);
						} else {
							temp2.push(obj);
						}
					} else {//该样品为平行样品，或者加标样品
						temp3.push(obj);
					}
				} else {
					// console.log(obj)
					temp4.push(obj);//普通样品
					// temp4.unshift(obj);
				}
			}
			for (var j in temp3) {
				var flag = false;
				var newTemp = JSON.parse(JSON.stringify(temp4));
				for (var k in newTemp) {
					if (temp3[j].parent == newTemp[k].parent) { //temp4[j]是temp3[k]的父样
						temp4.splice(Number(k) + 1, 0, temp3[j]);
						flag = true;
						break;
					}
				}
				if (!flag) {//平行或者加标样品没有找到父样
					temp4.push(temp3[j]);//普通样品
				}
			}
			return temp1.concat(temp2,temp5,temp4)
		},
		sampleSort(arr) { //质控类型：1空白；2平行；3加标；4标准样品；5标准系列
			var temp1 = [];//第一，无父样-标准系列样品
			var temp2 = [];//第二，无父样-室内空白
			var temp3 = [];//第三，无父样-室外空白
			var temp4 = [];//第四，无父样-标准样品
			var temp51 = [];//第五，有父样 - 室内
			var temp52 = [];//第五，有父样 - 室外
			var temp6 = [];//第六，普通样品
			var temp7 = [];//第七，加标父样
			console.log(arr)
			// debugger;
			for (var i in arr) { //遍历所有需要排序的样品
				// debugger
				var obj = arr[i];
				if(obj.qcType == null || obj.qcType == "" || obj.qcType == undefined){
					if(obj.parentCode != undefined && obj.parentCode != null && obj.parentCode != "" ){ //虚拟加标父样
						temp7.push(obj);
					}else{ //普通样品
						temp6.push(obj);
					}
					continue;
				}
				if(obj.group ==1){ //有父样
					if(obj.space ==2){//室外
						temp51.push(obj);
					}else{ //室内
						temp52.push(obj);
					}
				}else{	//等于2 或者为空 表示无父样
					if (obj.doStandard) { //标准系列样品
						temp1.push(obj);
					}else if(obj.space == 2 && obj.type ==1 ){ //室内2 - 空白1
						temp2.push(obj);
					}else if(obj.space == 1 && obj.type ==1 ){ //室外2 - 空白1
						temp3.push(obj);
					}else if(obj.type ==4 ){ //标准样品
						temp4.push(obj);
					}
				}
			}
			//目的：将加标父样排在普通父样之后
			var temp61 = [];//普通样品 + 虚拟样品
			for(var i in temp6){
				temp61.push(temp6[i]);
				for(var j in temp7){
					if(temp7[j].parentCode == temp6[i].sampleCode){
						temp61.push(temp7[j]);
					}
				}
			}
			//目的：先区分室内室外，再区分平行与其他
			var temp11 = [];//室外排序
			for(var j in temp51){ //对质控样品进行排序；先排室外：1室外；2室内
				if(temp51[j].type == 2){
					temp11.push(temp51[j]); //有父样1 - 平行样品
				}else{
					temp11.unshift(temp51[j]);
				}
			}
			var temp12 = [];//室内排序
			for(var j in temp52){ //对质控样品进行排序；先排室外：1室外；2室内
				if(temp52[j].type == 2){
					temp12.push(temp52[j]); //有父样1 - 加标样品
				}else{
					temp12.unshift(temp52[j]);
				}
			}
			temp11 = temp12.concat(temp11);
			for (var j in temp11) {
				var flag = false;
				var newTemp = JSON.parse(JSON.stringify(temp61));
				for (var k in newTemp) {
					if (temp11[j].parent == newTemp[k].parent) { //temp6[j]是 temp5[k]的父样
						temp61.splice(Number(k) + 1, 0, temp11[j]);//插入一条数据
						flag = true;
						break;
					}
				}
				if (!flag) {//平行或者加标样品没有找到父样
					temp61.push(temp11[j]);//普通样品
				}
			}
			return temp1.concat(temp2,temp4,temp3,temp61)
		},
		// 调用子元素函数 清空选中数据并关闭弹框
		toggleSelect() {
			this.$refs.addsampleRef.toggleSelection()

			this.addSamplepop = false;
		},

		// 已选样品勾选的值
		handleSelectionChange(val) {
			this.multipleSelection = val;
		},
		selectInit(row, index) { //判断样品列表是否可勾选 是qc样品不可勾选
			if (row.qcType == null || row.qcType == '' || row.qcType == undefined) {
				return true  //可勾选
			} else {
				// if(row.space == 1){
				// 	return true
				// }else{
					return false  //不可勾选
				// }

			}
		},
		// 添加标准系列 弹框弹出
		addStandardSeriesShow() {
			this.standardseriesshow = true;
			this.newOrEdit = 'new';
			this.standardSeriesForm = {
				code: '',
				configDate: this.util.date(),
				temperature: '',
				humcodeity: '',
				doUse: false,
				checker: '',
				configMan: JSON.parse(sessionStorage.getItem('laboratoryAccountInfo')).loginid,
			};
		},
		// 查看标准系列
		lookStandardSeriesShow(newOrEdit) {
			if(this.testpanelForm.equipment === "" || this.testpanelForm.equipment === null || this.testpanelForm.equipment === undefined){
				this.$notify({
					type:"warning",
					title:"警告",
					message:"请先选择主仪器",
				})
				return;
			}
			this.newOrEdit = newOrEdit;
			this.$http({
				method: 'post',
				apiUrl: '/detection/readCriterion.htm',
				params: { batch: this.testpanelForm.id,detectability:this.testpanelForm.detectability,equipment:this.testpanelForm.equipment },
				isJson: false,
			}).then(res => {
				if (res.code === 0) {
					if(newOrEdit == 'new'){
						if(res.data === null || res.data === undefined || res.data === ''){
							this.standardSeriesForm = {
								code: '',
								configDate: this.util.date(),
								temperature: '',
								humcodeity: '',
								doUse: false,
								checker: '',
								configMan: JSON.parse(sessionStorage.getItem('laboratoryAccountInfo')).loginid,
							};
						}else{
							this.standardSeriesForm = res.data;
						}
					}else{
						this.standardSeriesForm = res.data;
					}
					this.standardseriesshow = true;


				}

			})
		},

		readQcList() {
			this.$http({
				method: 'post',
				apiUrl: '/qc/readQcTypes.htm',
			}).then(res => {
				if (res.code == 0) {
					this.qcList = [];
					this.standarQc = [];
					this.allQcList = res.data;
					for (var i in res.data) {
						if (res.data[i].genre == 'QCB02') {
							this.qcList.push(res.data[i])
						} else if (res.data[i].genre == 'QCB01') {
							this.qcList.unshift(res.data[i])
						} else if (res.data[i].genre == 'QCB03') {
							this.standarQc.push(res.data[i])
						}
					}
					console.log(this.standarQc)
					// 给qc分类中的输入框和是否选中赋值
					for (var i in this.qcList) {
						this.$set(this.qcList[i], 'checkboxModel', false);
						this.$set(this.qcList[i], 'inputModel', 2);
					}

				}
			})
		},
		addQCShow() {
			this.addqcShow = true;
			// this.readQcList();
			// qc类型排序
			// function compare(property) {
			// 	return function (a, b) {
			// 		var value1 = a[property];
			// 		var value2 = b[property];
			// 		return value1 - value2;
			// 	}
			// }
			// this.typeQcSelect.itemList.sort(compare('genre'))
			// 设置qc分类绑定值

			// 如果选中父样 平行和加标 可用  如果没有选父样 空白可用
			if (this.multipleSelection.length == 0) {
				this.hasParentSample = false;
			} else {
				this.hasParentSample = true;
			}
			this.$http({
				method: 'post',
				apiUrl: '/resource/readStockListByDetecId.htm',
				params: { detecId: this.testpanelForm.detectability,detecBatch:this.testpanelForm.id },
				isJson: false,
			}).then(res => {
				for (var i in res.data) {

					res.data[i].nameBatch = res.data[i].materialName + '-' + res.data[i].batch
					res.data[i].delObj = res.data[i].number + '-' + res.data[i].batch
				}
				var obj = {};
				// res.data.filter(item=>!arr1.some(ele=>ele.id===item.id))
				 this.monitoringPoints  = res.data.reduce((cur,next) => {
					obj[next.delObj] ? "" : obj[next.delObj] = true && cur.push(next);
					return cur;
				},[])
				// this.monitoringPoints = res.data

			})


		},
		// 把选中的qc样品加入到已选样品中
		subQC() {
			var arrTemp = [];
			for (var j in this.qcList) { //

				// 如果qc类型的genre为QCB01 代表无父样，加入数量为输入框的个数
				if (this.qcList[j].genre == 'QCB01' && !this.hasParentSample) {
					if (this.qcList[j].checkboxModel) {
						var parent = this.util.generateMixed({number:32})
						for (var k = 1; k <= this.qcList[j].inputModel; k++) {
							var obj = {};
							obj.qcType = this.qcList[j].code;
							obj.qcTypeName = this.qcList[j].name;
							obj.genre = this.qcList[j].genre;
							obj.sampleName = this.qcList[j].name + k;
							obj.doStandard = false;
							obj.sampleCode = '/'
							// obj.taskName = '---';
							obj.doBlind = false;
							obj.doStandard = false;
							obj.parent = parent;
							obj.type = this.qcList[j].type;
							obj.space = this.qcList[j].space;
							obj.genre = this.qcList[j].genre;
							obj.group = this.qcList[j].group;
							arrTemp.push(obj)
						}
					}
					console.log(arrTemp)

				} else if (this.qcList[j].genre == 'QCB02' && this.hasParentSample) {
					// 如果qc类型的genre为QCB02 代表有父样，加入数量1，选中的父样下都加入
					if (this.qcList[j].checkboxModel) {
						for (var i in this.multipleSelection) {
							console.log(this.multipleSelection[i])
							if(this.multipleSelection[i].valueStyle == 1){
								if(this.qcList[j].type != 3){
									this.$notify({
										title:"警告",
										message:"加标父样只能加入室内加标为子样",
										type:"warning"
									})
									return;
								}
							}
							var obj = {};
							var a = Number(i) + Number(1)
							obj.qcType = this.qcList[j].code;
							obj.qcTypeName = this.qcList[j].name;
							var name = this.multipleSelection[i].sampleName == undefined ? '' : this.multipleSelection[i].sampleName + '-'
							obj.genre = this.qcList[j].genre;
							// obj.sampleName = name + this.qcList[j].name + a;
							obj.sampleName = name + this.qcList[j].name;
							obj.doStandard = false;
							obj.parentCode = this.multipleSelection[i].sampleCode;
							obj.parent = this.multipleSelection[i].parent;
							obj.doBlind = false;
							obj.doStandard = false;
							obj.sampleCode = '/';
							obj.type = this.qcList[j].type;
							obj.space = this.qcList[j].space;
							obj.genre = this.qcList[j].genre;
							obj.group = this.qcList[j].group;
							obj.valueStyle = this.multipleSelection[i].valueStyle
							// 父样标号和qcType组合判断,一个父样只能有一个室内平行和一个室内加标 ----
							// obj.qcTypeCode = this.qcList[j].code + this.multipleSelection[i].sampleCode;
							// for(var k in this.testpanelForm.sampleBeans){
							// 	var qcTypeCode = this.testpanelForm.sampleBeans[k].qcType +  this.testpanelForm.sampleBeans[k].parentCode
							// 	if(qcTypeCode == obj.qcTypeCode){
							// 		this.$notify({
							// 			type:"warning",
							// 			message: '“' + this.multipleSelection[i].sampleName + "”该样品已经存在子样" + this.qcList[j].name,
							// 			title:"警告"
							// 		})
							// 		return
							// 	}
							// }
							arrTemp.push(obj)
						}
					}
				}
			}
			// 如果选中加标父样，选中的父样下都加入
			if (this.checkboxParent) {
				for (var i in this.multipleSelection) {
					if(this.multipleSelection[i].valueStyle == 1){
						this.$notify({
							title:"警告",
							message:"加标父样只能加入室内加标为子样",
							type:"warning"
						})
						return;
					}
					var obj = {};
					obj.sampleName = this.multipleSelection[i].sampleName == undefined ? '' : this.multipleSelection[i].sampleName + '- 加标父样'
					obj.doBlind = false;
					obj.doStandard = false;
					obj.sampleCode = '/';
					obj.space = 2
					obj.parentCode = this.multipleSelection[i].sampleCode;
					obj.valueStyle = 1;
					obj.parent = this.util.generateMixed({number:32})
					arrTemp.push(obj)
				}
			}
			console.log(arrTemp)

			var arrTemp1 = []
			for (var i in this.monitoringPointsValue) { //穿梭器选中的样品是勾选的样品的id的数组的形式,遍历里面的id值 和源数据中的id对比，并把选中的数据加入arrTemp数组
				for (var j in this.monitoringPoints) {
					if (this.monitoringPointsValue[i] == this.monitoringPoints[j].id) {

						// this.monitoringPoints[j].sampleName = this.monitoringPoints[j].materialName;
						this.monitoringPoints[j].sampleName = this.monitoringPoints[j].materialName + '-' + this.monitoringPoints[j].batch;
						this.monitoringPoints[j].sampleCode = '/';
						this.monitoringPoints[j].doStandard = false;
						this.monitoringPoints[j].genre = "QCB03";

						// this.standarQc
						this.monitoringPoints[j].qcType = this.standarQc[0].code;
						this.monitoringPoints[j].qcTypeName = this.standarQc[0].name;

						// this.monitoringPoints[j].standardSample = this.monitoringPoints[j].hashcode; //标准物资再物料管理的id
						this.monitoringPoints[j].standardSample = this.monitoringPoints[j].batch + ";" + this.monitoringPoints[j].number;
						this.monitoringPoints[j].type = this.standarQc[0].type;
						this.monitoringPoints[j].space = this.standarQc[0].space;
						this.monitoringPoints[j].genre = this.standarQc[0].genre;
						this.monitoringPoints[j].group = this.standarQc[0].group;

						this.monitoringPoints[j].parent = this.util.generateMixed({number:32});
						arrTemp1.push(this.monitoringPoints[j])
					}
				}

			}
			for(var  i in arrTemp1){
				delete arrTemp1[i].id
			}
			if (arrTemp1.length != 0) {
				var list = this.util.repeatData({ old: this.testpanelForm.sampleBeans, new: arrTemp1, unique: 'standardSample' })
				// arrTemp.concat(list);
				this.testpanelForm.sampleBeans = this.sampleSort(list);
			}
			if (arrTemp.length != 0) {
				var list = this.testpanelForm.sampleBeans.concat(arrTemp)
				// var list = this.util.repeatData({ old: this.testpanelForm.sampleBeans, new: arrTemp, unique: 'sampleName' })
				this.testpanelForm.sampleBeans = this.sampleSort(list);
			}
			// console.log(this.testpanelForm.sampleBeans)
			this.closeaddqcShow()
		},


		// 关闭添加QC的弹框
		closeaddqcShow() {
			this.addqcShow = false;
			this.hasParentSample = false;
			this.monitoringPointsValue = [];
			this.monitoringPoints = [];
			for (var i in this.qcList) {
				this.$set(this.qcList[i], 'checkboxModel', false);
				this.$set(this.qcList[i], 'inputModel', 2);
			};
			this.activeName = "first";
			this.qcPlanDetail = {};
			this.checkboxParent = false; //加标父样
		},
		//提交检测单
		subUpdatebatch() {

			// 如果没有doStand  默认添加为false
			// for (var i in this.testpanelForm.sampleBeans) {
			// 	if (this.testpanelForm.sampleBeans[i].doStandard == undefined || this.testpanelForm.sampleBeans[i].doStandard == '') {
			// 		this.testpanelForm.sampleBeans[i].doStandard = false
			// 	}
			// }
			this.$refs.testpanelForm.validate((valid) => { //表单验证
				if (valid) {
					if (this.testpanelForm.analyst == this.testpanelForm.checker || this.testpanelForm.analyst == this.testpanelForm.auditor || this.testpanelForm.auditor == this.testpanelForm.checker) {
						this.$notify({
							title: "警告",
							message: "校核人员、检测人员、审核人员不能有相同的人",
							type: "warning"
						})
						return;
					}
					var data = {
						id: this.testpanelForm.id,
						detectability: this.testpanelForm.detectability,
						sampleBeans: this.testpanelForm.sampleBeans,
						code: this.testpanelForm.code,
						doSub: this.testpanelForm.doSub,
            offices:this.testpanelForm.offices
					}
					if(this.testpanelForm.assistEquipment.length > 3){
						this.$notify({
							title: "警告",
							message: "辅助仪器不可超过三个!",
							type: "warning"
						})
						return;
					}
					for(var i in this.testpanelForm.assistEquipment){
						if(this.testpanelForm.equipment == this.testpanelForm.assistEquipment[i]){
							this.$notify({
								title: "警告",
								message: "存在辅助仪器和主仪器重复!",
								type: "warning"
							})
							return;
						}
					}

					// 取主仪器id和名字
					for (var i in this.mainequipment) {
						if (this.testpanelForm.equipment == this.mainequipment[i].equipment) {
							data.equipment = this.testpanelForm.equipment;
							data.equipmentName = this.mainequipment[i].name;
						}
					}
					// 辅助仪器的id和名字
					var arrAssName = [];
					var arrAss = [];
					for (var i in this.assEquipment) {
						for(var j in this.testpanelForm.assistEquipment){
							if (this.testpanelForm.assistEquipment[j] == this.assEquipment[i].equipment) {
								arrAssName.push(this.assEquipment[i].name)
								arrAss.push(this.assEquipment[i].equipment)
							}
						}
					}

					data.assistEquipment = arrAss.join(";");
					data.assistEquipmentName = arrAssName.join(";");
					for (var i in this.userData) { //循环人员列表，对比检测人校核人共同完成人 取账户和名字
						if (this.testpanelForm.analyst == this.userData[i].account) {// 检测人
							data.analyst = this.userData[i].account;
							data.analystName = this.userData[i].name;
						}
						if (this.testpanelForm.checker == this.userData[i].account) {// 校核人
							data.checker = this.userData[i].account;
							data.checkerName = this.userData[i].name;
						}
						if (this.testpanelForm.togetherWith == this.userData[i].account) {
							data.togetherWith = this.userData[i].account;
							data.togetherWithName = this.userData[i].name;
						}
						// auditorName
						if (this.testpanelForm.auditor == this.userData[i].account) {
							data.auditor = this.userData[i].account;
							data.auditorName = this.userData[i].name;
						}
					}
					console.log(data);
					this.checkBatch(data)
				} else {
					return false;
				}
			});

		},
		// 验证质控计划
		checkBatch(data) {
      this.isRepeat = false;
			var flag = true;
      this.isLoading = true;
			this.$http({
				method: 'post',
				apiUrl: '/detection/checkBatchByQcPlan.htm',
				params: data,
				isJson: true,
			}).then(res => {
        this.isLoading = false;
				if (res.code === 0) {
					if (!res.data.result) {
						this.$confirm(res.data.msg, '是否继续', {
							confirmButtonText: '确定',
							cancelButtonText: '取消',
							type: 'warning'
						}).then(() => {
							// flag = true;
							this.updateTestBatch(data)
						}).catch(() => {
							// flag = false;
              this.isRepeat = true;
							this.$message({
								type: 'info',
								message: '已取消提交'
							});
						});
					} else {
						this.updateTestBatch(data)
					}
				}

			})

		},
		updateTestBatch(data) {
			this.$http({
				method: 'post',
				apiUrl: '/detection/updateTestBatch.htm',
				params: data,
				isJson: true,
        isLoading:true,
			}).then(res => {
				this.isRepeat = true;
				if (res.code === 0) {
					this.$notify({
						type: 'success',
						message: '提交成功',
						title:"成功"
					})
					this.getTestBatchs(this.testItemQuery)
					this.closePanel();
				}

			})
		},
		closePanel() {
			this.editpanelshow = false;
			this.isRepeat = true;
			this.testpanelForm = {  //检测单表单
				analyst: "",
				assistEquipment: "",
				equipment: "",
				checker: "",
				togetherWith: "",
				sampleBeans: [],
        offices:'',
			};
      this.testpanelRules = {
        equipment: [
        	{ required: true, message: '请选择仪器类型', trigger: 'change' },
        ],
        checker: [{ required: true, message: '请选择校核人员', trigger: 'change' }],
        offices:[{ required: true, message: '请选择', trigger: 'blur' }],
			};

		},

		handleSizeChange: function(val) {
			this.testItemQuery.pageCount = val;
		},
		handleCurrentChange: function(val) {
			this.testItemQuery.page = val;
		},

		testbatchrowselect: function(now, old) {
			// console.log(now,old)
		},
	}
}

</script>
<style scoped>
  .panelsList .infoitem{
    width: calc(100%/4);
  }
.editpanelPop .el-form-item {
	width: 32%;
	display: inline-block;
	margin-bottom: 8px;
}

.editpanelPop .form {
	height: 155px;
}

.editpanelPop .el-form-item .el-select {
	width: 100%
}

.editpanelPop .elTab {
	height: calc(100% - 155px);
	padding: 0 20px;
}
</style>
<style>
.editpanelPop .el-tabs,
.editpanelPop .el-tabs .el-tab-pane {
	height: 100%;
}

.editpanelPop .el-tabs .el-tabs__content {
	height: calc(100% - 50px)
}

.editpanelPop .el-tabs .el-tabs__header {
	margin: 0 0 10px;
}

.editpanelPop .el-tabs .el-tab-pane .el-table {
	height: calc(100% - 33px);
	/*overflow-y: auto;*/
}

.addSampleForm .el-dialog {
	height: 70%;
}

.addSampleForm .el-dialog .el-form-item {
	margin-bottom: 20px;
}

.addSampleForm .el-dialog .el-dialog__body {
	height: calc(100% - 85px);
	padding: 10px;
}

.addSampleForm .el-dialog .el-dialog__body .form {
	height: 60px;
}

.addSampleForm .el-dialog .el-dialog__body .form .el-form-item {
	width: 49%;
	display: inline-block;
}

.addSampleForm.addSampleForm1 .el-dialog .el-dialog__body .form .el-form-item {
	width: 33%;
	display: inline-block;
}

.addSampleForm .el-dialog .el-dialog__body .sampleList {
	height: 100%;
}

.addSampleForm .el-dialog .el-dialog__footer {
	height: 45px;
	line-height: 45px;
	padding: 0 20px !important;
}

.sampleList>div,
.sampleList>div>div {
	height: 100%;
}

.addSampleForm .separaterowTable {
	height: calc(100% - 60px) !important;
}

.sampleList .seachTip {
	height: 68px;
	padding: 10px 0px 20px 15px;
}

.sampleList .seachTip {
	height: 68px;
	padding: 10px 0px 20px 15px;
}

.standardseries .el-dialog {
	height: 80%;
	margin-top: 10vh !important;
}

.sampleList .seachTip .isZuJian {
	margin: 0 12px;
}


/*.controlsPosition .el-input-number__increase,.controlsPosition .el-input-number__decrease*/


/*注释的为添加qc时数字框*/

.addSampleForm.standardseries .controlsPosition .el-input-number__decrease,
.addSampleForm.standardseries .controlsPosition .el-input-number__increase {
	display: none;
}

.addQCdialog .padd10 {
	width: 100%;
	padding: 10px;
}

.addQCdialog .inlineblock.with70 {
	width: 100px;
}

.addQCdialog .inlineblock.with70 .el-input-number {
	width: 80%;
}

.addQCdialog .inlineblock.with70 .el-input-number .el-input__inner {
	padding-left: 25px;
	padding-right: 20px;
	text-align: left;
}

.addQCdialog .width100.inlineblock {
	width: 32%;
	margin-bottom: 15px;
}

.addQCdialog .el-transfer-panel {
	width: 40%;
}

.addQCdialog .text85 {
	width: 85px;
	text-align: right;
	margin-right: 10px;
}

.addQCdialog .sampleType li.sample3 {
	width: 100%;
	margin-top: 20px;
}
.addQCdialog .el-tabs{
	height:100%;
}
.addQCdialog .el-tabs__content{
	height:calc(100% - 50px);
}
.addQCdialog .el-tabs__content .el-tab-pane{
	height:100%;
}

.borderNone input {
	border: none;
}

.el-input-number__decrease,
.el-input-number__increase {
	width: 20px !important;
}

.el-tooltip__popper.is-dark {
	max-width: 800px;
}

.transferQc .el-transfer-panel__header .el-checkbox__input {
	display: none;
}

.transferQc .el-transfer-panel:nth-last-of-type(1) .el-transfer-panel__filter {
	display: none;
}
</style>
